package com.itheima.job;

import java.util.Arrays;

public class Test04 {
    public static void main(String[] args) {
        Mycontainer<String> mt = new Mycontainer<>();
        for (int i = 0; i < 13; i++) {
            mt.add("数据"+i);
        }
        System.out.println(mt.size());
        System.out.println(mt);
    }
}

class Mycontainer<T>{
    //private T[] datas = new T[10];  不能直接实例化类型参数'T'
    private Object[] datas = new Object[10];
    private int index = 0;

    public void add(T t){
        if (index>=datas.length) {
            Object[] temp = new Object[(int)(datas.length*1.5)];
            System.arraycopy(datas,0,temp,0,datas.length);
            datas = temp;
        }
        datas[index] = t;
        index++;
    }
    public int size(){
        return index;
    }

    @Override
    public String toString() {
        return "Mycontainer{" +
                "datas=" + Arrays.toString(datas) +
                ", index=" + index +
                '}';
    }
}
